package com.objecteffects.ilmp.service;

import java.util.List;

import com.google.inject.Inject;
import com.google.inject.persist.Transactional;

import com.objecteffects.ilmp.model.UserEntity;
import com.objecteffects.ilmp.persist.api.IUserEntityDao;
import com.objecteffects.ilmp.util.logger.InjectLogger;

import org.slf4j.Logger;

/**
 * @author Rusty Wright
 */
public class UserEntityService {
    @InjectLogger
    private Logger log;

    private final IUserEntityDao dao;

    /** */
    @Inject
    UserEntityService(final IUserEntityDao _dao) {
        this.dao = _dao;
    }

    @Transactional
    public void save(final UserEntity input) {
        this.dao.save(input);
    }

    @Transactional
    public void saveAll(final List<UserEntity> input) {
        for (final UserEntity each : input) {
            if (each != null) {
                this.dao.save(each);

                this.log.debug("each: {}", each);
            }
        }
    }

    @Transactional
    public UserEntity findByUserName(final String username) {
        return this.dao.findByUserName(username);
    }

    @Transactional
    public UserEntity findByHash(final String hash) {
        return this.dao.findByHash(hash);
    }

    @Transactional
    public List<UserEntity> findAll() {
        return this.dao.findAll();
    }

    @Transactional
    public UserEntity findById(final Long id) {
        return this.dao.findOne(id);
    }

    @Transactional
    public void deleteById(final Long entityId) {
        this.dao.deleteById(entityId);
    }

    @Transactional
    public UserEntity update(final UserEntity entity) {
        return this.dao.update(entity);
    }

    @Transactional
    public UserEntity refresh(final UserEntity entity) {
        return this.dao.refresh(entity);
    }
}
